package com.syni.mdd.yhd.common.all.listen.order;

import com.syni.mdd.yhd.common.all.entity.record.ReOrderRefundLog;
import com.syni.mdd.yhd.common.all.service.record.ReOrderRefundLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @className OrderListener
 * @description TOO
 * @Author cfx
 * @DATE 2019/8/8 15:46
 * @VERSION 1.0
 **/
@Component
public class OrderRefundCompleteListener implements ApplicationListener<OrderEvent> {
    public final static String MODEL_COMPLETE = "orderRefundComplete";

    private final Logger log = LoggerFactory.getLogger(getClass());

    @Autowired
    ReOrderRefundLogService reOrderRefundLogService;

    @Async
    public void onApplicationEvent(OrderEvent orderEvent) {
        String model = orderEvent.getSource().toString();
        if (model.equals(MODEL_COMPLETE)) {
            if (orderEvent.getRefundChannel().equals(ReOrderRefundLog.ALI_PAY)){
                reOrderRefundLogService.addRefundLogRecordByAli(orderEvent.getBmsDxOrder().getId(), orderEvent.getRefundMoney(), orderEvent.getRefundTag());
            } else if (orderEvent.getRefundChannel().equals(ReOrderRefundLog.WX_PAY)) {
                reOrderRefundLogService.addRefundLogRecordByWx(orderEvent.getBmsDxOrder().getId(),orderEvent.getRefundMoney(),orderEvent.getRefundTag());
            }
        }
    }
}
